package com.hbk.service.impl;

import com.hbk.base.constant.HbkConstant;
import com.hbk.service.ICacheService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CacheServiceImpl implements ICacheService {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    public String getIndexCache(){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        String value = ops.get(HbkConstant.INDEX_CACHE);
        return value;
    }

    public void setIndexCache(String value){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.set(HbkConstant.INDEX_CACHE, value, HbkConstant.INDEX_CACHE_TIME);
    }

    public void deleteIndexCache(){
        stringRedisTemplate.delete(HbkConstant.INDEX_CACHE);
    }

    public String getNavCache(){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        String s = ops.get(HbkConstant.NAV_CACHE);
        return s;
    }

    public void setNavCache(String value){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.set(HbkConstant.NAV_CACHE, value, HbkConstant.INDEX_CACHE_TIME);
    }

    public void deleteNavCache(){
        stringRedisTemplate.delete(HbkConstant.NAV_CACHE);
    }
}
